import os
import shutil
from lib.log import Loggers

log = Loggers(name="OS Operations")


class OsOperations:

    @classmethod
    def mkdir(cls, directory: str):
        if os.path.exists(directory):
            log.warning("已存在目录，无法创建")
            return directory
        else:
            return os.mkdir(directory)

    @classmethod
    def add_os_env(cls, env_name, env_value):
        os.environ[env_name] = env_value
        log.warning("已添加系统变量 %s ==> %s" % (env_name, env_value))

    @classmethod
    def copy(cls, src: str, dest: str):
        return shutil.copy(src, dest)

    @classmethod
    def get_directory_detail(cls, directory: str):
        details = dict()
        if os.path.exists(directory) and os.path.isdir(directory):
            for root, dirs, files in os.walk(directory):
                details[root] = [dirs, files]
        return details


